<?
	include('top.php');
	include('conn.php');
	session_start();
	$msg='';
	if($_REQUEST['submit']=='Save Record')
	{
		$custtype=$_REQUEST['custtype'];
		$prefix=$_REQUEST['prefix'];
        $name=$_REQUEST['name'];
     	$address=$_REQUEST['address'];
		$city=$_REQUEST['city'];
		$email=$_REQUEST['email'];
		$phoneno=$_REQUEST['phoneno'];
		$enteredby=$_SESSION['username'];
		
		$sqlc="select count(*) cnt from customermast where status = 0 and custdesc='".$name."'";
		$resc=mysql_query($sqlc);
		$rowc=mysql_fetch_assoc($resc);
		if($rowc['cnt']==0)
		{
			$sql="insert into customermast(custtype,custdesc,address,city,email,phoneno, enteredby,entrydt)
				values('".$custtype."','".$name."','".$address."','".$city."','".$email."','".$phoneno."','".$enteredby."',sysdate())";
			$res=mysql_query($sql);
			if($res)
				$msg='Record saved successfully';
				?>
				<script>window.location.href = 'customermaster.php'</script>			
				<?
		}
		else
		{
				$msg='Record Already Exist';			
		}		
	}
?>
 <script type="text/javascript" src="customermain.js"></script>
 <script language="javascript">
 function SearchCtrl($scope, $http) {
        $scope.url = 'savecustomer.php'; // The url of our search
        // The function that will be executed on button click (ng-click="search()")
        $scope.search = function() {
            // Create the http post request
            // the data holds the keywords
            // The request is a JSON request.  i want the data in $_POST
            $http.post($scope.url, { "name" : $scope.name,"address" : $scope.address,"city" : $scope.city,"custtype" : $scope.custtype,"email" : $scope.email,"phoneno" : $scope.phoneno}).
            success(function(data, status) {
                $scope.status = status;
                $scope.data = data;
                $scope.result = data; // Show result from server in our <pre></pre> element
            }).
            error(function(data, status) {
                $scope.data = data || "Request failed";
                $scope.status = status;         
            });
        };
	//alert(" ");
}

function deletecust(name0)
{
	//alert(name0);
	if (confirm('Do you really want to delete this record?')) {
	$.post( "customerdelete.php?", { name: name0})
	.done(function( data ) {
	alert( "Record Deleted ");// + data );
	});
	window.location.href = 'customermaster.php';
	}
	//var jqxhr = $.post( "customerdelete.php", function() {
	//alert( "success" );
	//})
}

 function customeredit(Referenceno,param2)
  {
	//alert(Referenceno);
	window.location.href = Referenceno;	
  }
 </script>
 
  <td> <label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Admin / Customer Master</label></td>
<div  align="center">
			<div ng-controller="SearchCtrl">
			<table  cellpadding="4" id="box-table-a" cellspacing="4" border="1" width="650" bgcolor="#000000" style="background-color:#DFEBF9;">
				<tr><td colspan="3" align="center" style="text-align:center; color:#FF0000;">{{result}}</td></tr>
				<tr><td colspan="3" align="center" style="text-align:center; font-weight:bold;">Customer Master</td></tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Type</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="custtype" id="custtype" class="smallInput" ng-model="custtype" style="width:290px; font-size:12px; font-weight:bold;" >
							<option value="CUSTOMER">CUSTOMER</option>
							<option value="DISTRIBUTOR">DISTRIBUTOR</option>
							<option value="AGENT">AGENT</option>
						</select>
					</td>
				</tr>
                            
                <tr bgcolor="#FFFFFF">
                    <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Prefix</label></td>
                    <td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
        			<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<select  name="prefix" id="prefix" class="smallInput" ng-model="prefix" placeholder="Prefix" style="width:290px; font-size:12px; font-weight:bold;" >
							<option value="MR">MR</option>
							<option value="MRS">MRS</option>
							<option value="M/S">M/S</option>
						</select>
				 </td>
                 
				<tr bgcolor="#FFFFFF">
                 	<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Name</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="name" name="name" class="smallInput" required= "" ng-model="name" placeholder="Name" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>

                <tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Address</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
					 <textarea name="address" cols="45" rows="3" class="smallInput" id="address" ng-model="address"  placeholder="Address" style="width:280px;font-size:12px; text-align:left; font-weight:bold;"></textarea>
					</td>
				 </tr>
                 
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">City</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="city" name="city" class="smallInput" required= "" ng-model="city" placeholder="City" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Email Id</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="email" name="email" class="smallInput" ng-model="email" placeholder="Email Id" style="width:280px;text-align:left; font-size:12px; font-weight:bold;" />
					</td>
				</tr>
				<tr bgcolor="#FFFFFF">
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">Phone</label></td>
					<td ><label style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">:</label></td>
					<td style="text-align:left; font-size:14px; color:#333333; font-weight:bold; vertical-align:middle;">
						<input type="text" id="phoneno" name="phoneno" class="smallInput" ng-model="phoneno" placeholder="Phone No" style="width:280px; text-align:left; font-size:12px; font-weight:bold;" />
					</td>
		     	</tr>
               
				<tr> 
					<td align="center" colspan="3" style="background-color:#BBE2EE">
					<button type="submit" class="btn" ng-click="search();">Save</button>
				<!--	<button type="submit" class="btn" name="test" onclick="chg();">test</button> -->
					</td>
				</tr>
			</table>
			
		</div>
			
			<div  ng-controller="customer" id="customer">
				<div> <a ng-click="refreshGrid()"> Refresh Grid </a></div>
		        <div class="gridStyle1" ng-grid="gridOptions"></div>
			</div>

</div>
</body>
</html>
